package com.turing.post.tuxedo.util;

import java.io.Serializable;
import java.math.BigInteger;

import org.jdom2.Element;

import com.turing.post.util.PCPSApplicationException;

/**
 * 支付交易输入
 * 
 * @author yxb
 * 
 */
@SuppressWarnings("serial")
public class IPaid extends TransRequest implements Serializable {
	/**
	 * 其他发生额(分)
	 */
	public BigInteger otherPaidAmount = BigInteger.ZERO;

	/**
	 * 业务类型
	 */
	public String businessType = null;

	/**
	 * 支付对象
	 */
	public PaidObj paidObj = new PaidObj();

	/**
	 * 会员卡对象(可选)
	 */
	public MemberShipObj memberShipObj = new MemberShipObj();

	/**
	 * 附加数据对象
	 */
	public AdditionalObj additionalObj = new AdditionalObj();

	/**
	 * 产生计算MAC的域
	 */
	@Override
	protected void generateMacField() {
		// 仅处理第1个卡号
		for (CardPaidObj cpo : paidObj.cplist) {
			appendMacField(cpo.cardObj.cardNo);
			appendMacField(cpo.passwd);
			// appendMacField(cpo.amount.toString());
			break;
		}
	}

	/**
	 * 解析交易请求私有报文体
	 * 
	 * @param reqBody
	 * @throws Exception
	 */
	@Override
	protected void parseReqBodyXml(Element reqBody) throws PCPSApplicationException {
		// 其他支付额
		otherPaidAmount = TransXmlHelper.getInteger(reqBody,
				TransXmlHelper.XML_NODE_OtherPaidAmount);
		// 业务类型
		businessType = TransXmlHelper.getOptionalString(reqBody,
				TransXmlHelper.XML_NODE_BusinessType);
		// Paid
		Element elnode = reqBody.getChild(TransXmlHelper.XML_NODE_Paid);
		if (elnode == null)
			ParaseException.TransParamException("not found Paid!");
		paidObj.parsePaidObj(elnode);

		// MemberShip(可选)
		elnode = reqBody.getChild(TransXmlHelper.XML_NODE_MemberShip);
		if (elnode != null)
			memberShipObj.parseMemberShipObj(elnode);

		// AdditionalObj(可选)
		elnode = reqBody.getChild(TransXmlHelper.XML_NODE_Additional);
		if (elnode != null)
			additionalObj.parseAdditionalObj(elnode);
	}
}
